package com.mercycrazy.recruit.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 性别枚举类定义
 *
 * @author <a href="mailto:1443424326@qq.com">mercycrazy</a>
 * @since 2023-01-15
 */
@Getter
@AllArgsConstructor
public enum Sex {

    WOMAN(0, "女"),
    MAN(1, "男"),
    SECRET(2, "保密"),
    ;

    private final Integer type;
    private final String value;

    /**
     * <h2>根据 type 获取到 Sex</h2>
     * */
    public static Sex of(Integer type) {

        Objects.requireNonNull(type);

        return Stream.of(values())
                .filter(bean -> bean.type.equals(type))
                .findAny()
                .orElseThrow(
                        () -> new IllegalArgumentException(type + " not exists")
                );
    }
}
